//
//  YSVoiceRoomController.m
//  YouSheng
//
//  Created by aaa on 16/8/24.
//  Copyright © 2016年 FanShuHan. All rights reserved.
//

#import "YSVoiceRoomController.h"
#import "YSRoomUserCell.h"


static CGFloat const margin = 10;
static NSString * const ID = @"roomUserCell";

@interface YSVoiceRoomController ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property (weak, nonatomic) IBOutlet UICollectionView *roomUsersCollection;
@end

@implementation YSVoiceRoomController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"语音房间";
    
    [self setupCollectionView];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated {
    self.tabBarController.tabBar.hidden = NO;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)setupCollectionView {
    // 创建布局
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    
    // 设置cell尺寸
    CGFloat width = (_roomUsersCollection.frame.size.width - 3 * margin) / 4;
    CGFloat height = (_roomUsersCollection.frame.size.height - margin) / 2;
    layout.itemSize = CGSizeMake(width, height);
    layout.minimumInteritemSpacing = margin;
    layout.minimumLineSpacing = margin;
    _roomUsersCollection.collectionViewLayout = layout;
    _roomUsersCollection.backgroundColor = [UIColor blackColor];
    
    _roomUsersCollection.dataSource = self;
    _roomUsersCollection.delegate = self;
    _roomUsersCollection.scrollEnabled = NO;
    
    // 注册cell
    [_roomUsersCollection registerNib:[UINib nibWithNibName:NSStringFromClass([YSRoomUserCell class]) bundle:nil] forCellWithReuseIdentifier:ID];
}

#pragma mark - UICollectionViewDataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 8;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    // 从缓存池取
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    
    return cell;
}
#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    [self showAlertController];
}

- (void)showAlertController {
    NSString *createFriend = @"添加好友";
    NSString *seeInfo      = @"看资料";
    NSString *sendGift     = @"送礼物";
    NSString *report       = @"举报";
    NSString *cancel       = @"取消";
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *createFriendAction = [UIAlertAction actionWithTitle:createFriend style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        
    }];
    
    UIAlertAction *seeInfoAction = [UIAlertAction actionWithTitle:seeInfo style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        
        
    }];
    
    UIAlertAction *sendGiftAction = [UIAlertAction actionWithTitle:sendGift style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    UIAlertAction *reportAction = [UIAlertAction actionWithTitle:report style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancel style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertController addAction:createFriendAction];
    [alertController addAction:seeInfoAction];
    [alertController addAction:sendGiftAction];
    [alertController addAction:reportAction];
    [alertController addAction:cancelAction];
    [self presentViewController:alertController animated:YES completion:nil];
}

@end
